-- blood_altar
-- created by cheny
-- 鲜血祭坛

return {
    -- 判断
    canTrigger = function(args)
        -- 找一下当前有没有祭坛
        for pos = 1, GRID_SIZE do
            local grid = DungeonM.getGridByPos(pos);
            if grid.type == GRID_TYPE_BLOOD_ALTAR
                and grid.state ~= GRID_STATE_DISABLE
                and grid:isOpened() then
                -- 已经打开未失效
                return true;
            end
        end
        return false;
    end,

    -- 触发
    trigger = function(args)
        -- 当前有的圣器
        local equips = {};
        local holyItems = HolyItemsM.getAllHolyItems();
        for _, classId in pairs(holyItems) do
            if EquipM.hasEquipment(classId) then
                table.insert(equips, classId);
            end
        end

        -- 随机升级
        local index = math.random(#equips);
        local classId = equips[index];
        -- 先尝试升级先祖
        if DungeonActionM.go("holy_items_extra_improve", 0, classId) then
            return true;
        elseif DungeonActionM.go("holy_items_base_improve", 0, classId) then
            return true;
        end

        return false;
    end,
};
